<template>
  <div class>
    <h5 class="titleInfo">医院评价</h5>
    <el-form label-width="130px" ref="params" :rules="rules" :model="params">
      <el-row>
        <el-col :span="24">
          <el-form-item label="医生名称" prop="doctorId">
            <el-select filterable placeholder="请选择" @change="selectfn" v-model="params.doctorId">
              <el-option v-for="item in doctor" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医生评分">
            <span class="spanToInput"></span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医生服务" prop="doctorServerStar">
            <div style="padding-top: 10px;">
              <el-rate v-model="params.doctorServerStar"></el-rate>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医生效果" prop="doctorEffectStar">
            <div style="padding-top: 10px;">
              <el-rate v-model="params.doctorEffectStar"></el-rate>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="医生专业" prop="doctorProfessionStar">
            <div style="padding-top: 10px;">
              <el-rate v-model="params.doctorProfessionStar"></el-rate>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="医生评价" prop="doctorContents">
            <div style="padding-top: 10px;">
              <el-input
                type="textarea"
                :rows="2"
                v-model="params.doctorContents"
                placeholder="请输入内容最大不超过300"
                :maxlength="300"
              ></el-input>
            </div>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
const vaildateStart = (rule, value, callback) => {
  if (!value) {
    callback(new Error("不能低于一星"));
  } else {
    callback();
  }
};
export default {
  props: {
    doctor: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      rules: {
        doctorId: [
          {
            required: true,
            message: "医生不能为空",
            trigger: "blur"
          }
        ],
        doctorServerStar: [
           {
            validator: vaildateStart,
            trigger: "blur"
          }
        ],
        doctorEffectStar: [
          {
            validator: vaildateStart,
            trigger: "blur"
          }
        ],
        doctorProfessionStar: [
         {
            validator: vaildateStart,
            trigger: "blur"
          }
        ],
        doctorContents: [
          {
            required: true,
            message: "医生评价不能为空",
            trigger: "blur"
          }
        ]
      },
      value1: 0,
      params: {}
    };
  },
  methods: {
    checkfn() {
      let abc = "";
      this.$refs["params"].validate(valid => {
        console.log(123, valid);

        if (valid) {
          abc = true;
        } else {
          this.$message({
            message: "请完善信息再提交",
            type: "warning"
          });
          abc = false;
        }
      });
      return abc;
    },
    selectfn(val) {
      // console.log(val,this.list)
      let arr = this.doctor.filter(res => {
        return res.id == val;
      });
      this.params.doctorName = arr[0].name;
    }
  }
};
</script>
